package com.shiwaixiangcun.customer.base;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.shiwaixiangcun.customer.R;

/**
 * Author   Administrator
 * Date     2018/3/10
 * Desc     eg
 *
 * @author Administrator
 */
@SuppressLint("Registered")
public abstract class BaseRefreshActivity extends BaseActivity {

    /**
     * 起始页码
     */
    protected int pageIndex = 0;
    /**
     * 每页数目
     */
    protected int pageCount = 20;
    private FrameLayout mToolbarLayout;
    private RecyclerView mRefreshContent;
    private SmartRefreshLayout mSmartRefreshLayout;
    private BaseQuickAdapter mBaseQuickAdapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_refresh);

        initViewAndEvent();


    }

    protected void initViewAndEvent() {
        mToolbarLayout = findViewById(R.id.layout_toolbar);
        mRefreshContent = findViewById(R.id.rv_content);
        mSmartRefreshLayout = findViewById(R.id.refreshLayout);


        mRefreshContent.setLayoutManager(new LinearLayoutManager(this));

        mSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                pageIndex = 0;
                startRefresh(pageIndex, pageCount);
            }
        });
    }

    /**
     * 开始刷新
     *
     * @param pageIndex
     * @param pageCount
     */
    protected abstract void startRefresh(int pageIndex, int pageCount);


    protected void setToolBar(int id) {
        View toolView = LayoutInflater.from(mContext).inflate(id, null, false);
        mToolbarLayout.addView(toolView);
    }

    protected void setContent(int contentId) {
        View contentView = LayoutInflater.from(mContext).inflate(contentId, null, false);
        mRefreshContent.addView(contentView);

    }
}
